package userInterfaces;

import java.io.IOException;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

import managerBean.CarrelloManagerBean;
import managerBean.WishlistManagerBean;
import model.Pacchetto;

@ManagedBean(name="WishlistManagedBean")
@SessionScoped
public class WishlistManagedBean {

	@EJB
	private WishlistManagerBean wishMgrBean;
	
	private List<Pacchetto> pacchetti;
	private int storedId;
	private int idWishlist;
	
	
	
	public int getIdWishlist() {
		return idWishlist;
	}

	public void setIdWishlist(int idWishlist) {
		this.idWishlist = idWishlist;
	}

	@PostConstruct
	public void init() {
		System.err.println(" inizializzo wishlistbean");
	}
	
	public int getStoredId() {
		return storedId;
	}

	public void setStoredId(int storedId) {
		this.storedId = storedId;
	}

	public WishlistManagedBean() {
		super();
	}

	public List<Pacchetto> getPacchetti() {
		this.pacchetti=wishMgrBean.getPacchettiMgr();
		return pacchetti;
	}

	public void setPacchetti(List<Pacchetto> pacchetti) {
		this.pacchetti = pacchetti;
	}
	
	public void rimuoviPacchetto(int idPacchetto){
		wishMgrBean.rimuoviPacchettoMgr(idPacchetto);
	}
	public void storeNbuy(int idPacchetto,int idWishlist){
		this.idWishlist=idWishlist;
		System.err.println("idpacchetto = "+idPacchetto);
		this.storedId=idPacchetto;
		System.err.println("storedId= "+storedId);

		try {
			FacesContext.getCurrentInstance().getExternalContext().redirect("cliente/offerta.xhtml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void rimuoviPacchettoRedir(int idPacchetto){
		wishMgrBean.rimuoviPacchettoRedirMgr(idPacchetto,this.idWishlist);
		try {
			FacesContext.getCurrentInstance().getExternalContext().redirect("../home.xhtml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
	
}
